package job

import (
	"git.supremind.info/product/box/vehicle/common"
	"git.supremind.info/product/box/vehicle/internal/dao"
	"git.supremind.info/product/box/vehicle/internal/kafka"
	"git.supremind.info/product/box/vehicle/internal/s3"
	"git.supremind.info/product/box/vehicle/internal/util"
	"time"
)

// 推送数据到平台端
func PushModelDataToPlatform() {
	if !kafka.GetInstance().Enabled() {
		return
	}
	if !s3.PlatformInstance().Enabled() {
		return
	}

	events := dao.GetUnPushModelHisDatas()
	if events != nil && len(events) > 0 {
		for _, event := range events {
			UploadFileToPlatform(event)
		}
	} else {
		time.Sleep(5 * time.Second)
	}
}

func UploadFileToPlatform(event dao.VehicleModelData) {
	var data dao.ModelData
	err := util.ConvByJson(event.Data, &data)
	if err != nil {
		common.Logger.Errorf("insert vehicleModelChemical error %v", err)
		return
	}

	if util.IsNotBlank(data.SideImageUrl) {
		//url, err := s3.PlatformInstance().PutObject( ,data.SideImageUrl)

	}
	if util.IsNotBlank(data.HeadImageUrl) {
		s3.PlatformInstance().PutObject()

	}
}
